package com.site.wisdom_construction.controller.iotModule;

import com.alibaba.fastjson.JSONObject;
import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.iotModule.HighSupportsService;
import com.site.wisdom_construction.util.HttpRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/3/7
 * @Description
 */
@Api(tags = "高支模信息接口")
@RestController
@RequestMapping("HighSupports")
@CrossOrigin
public class HighSupportsController {
    @Autowired
    private HighSupportsService highSupportsService;

    @ApiOperation(value = "高支模监测_趋势图", notes = "")
    @PostMapping("/findHighSupports")
    public OneDataResult findHighSupports(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(highSupportsService.findHighSupports(map));
        return oneDataResult;
    }


    @ApiOperation(value = "高支模实时数据", notes = "")
    @PostMapping("/selectHighSupports")
    public OneDataResult selectHighSupports(@RequestBody Map<String, Object> map) {
        OneDataResult oneDataResult = new OneDataResult();
        JSONObject jsonObject = new JSONObject();
        HttpRequest httpRequest =new HttpRequest();
        String path = "http://platform.youshucloud.com/wis/api/data/curNodeData";
        jsonObject = httpRequest.StringDataJson(path," {\n" +
                "        appId: \"zygeo\",\n" +
                "        appKey: \"NlkhfHIYG378LJHhuNvelh8Gklhfq3Hv\",\n" +
                "        companyId: 205143,\n" +
                "        projectId: 101194,\n" +
                "        nodeIds: [7515, 7516, 7517, 7518, 7519, 7520]\n" +
                "      }");
        oneDataResult.setData(jsonObject);
        return oneDataResult;
    }

    @ApiOperation(value = "删除高支模报警信息", notes = "测试数据:")
    @PostMapping("/deleteHighSupports")
    public JsonResult deleteHighSupports(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        List<Integer> list = (List<Integer>) map.get("list");
        int l = 0;
        Map mapR = new HashMap();
        for (int i = 0;i<list.size();i++){
            mapR.put("id",list.get(i));
            int a = highSupportsService.deleteHighSupports(mapR);
            l+=a;
        }
        if (l>=1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除高支模数据信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除高支模数据信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询高支模数据信息", notes = "测试数据:")
    @PostMapping("/findHighSupportsByPage")
    public Page findHighSupportsByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(highSupportsService.Total(map));
        page.setItems(highSupportsService.findHighSupportsByPage(map));
        return page;
    }

}
